#ifndef OutputWindow_H
#define OutputWindow_H

#include <QtGui>

// PHC: Two banks of house faders (6-chan each) plus 2x 4-chan spot fader
#define NUM_OUTPUT_FADERS 22

#include "SimpleChannel.h"

class DmxClient;

class DmxChannel : public SimpleChannel
{
	Q_OBJECT
	
	Q_PROPERTY(int dmxNum READ dmxNum WRITE setDmxNum);
	Q_PROPERTY(bool enabled READ isEnabled WRITE setIsEnabled);
	Q_PROPERTY(bool hold READ isHold WRITE setIsHold);

public:
	DmxChannel(DmxClient *client, QString chanName="", int num=1, int dmxNum=1)
		: SimpleChannel(chanName, num, 255)
		, m_dmxNum(dmxNum)
		, m_isEnabled(true)
		, m_isHold(false)
		, m_client(client)
		, m_mainValue(255)
		, m_holdTransmit(false)
	{}
	
	int dmxNum()		{ return m_dmxNum; }
	bool isEnabled()	{ return m_isEnabled; }
	bool isHold()		{ return m_isHold; }
	
	DmxClient *client()	{ return m_client; }
	
	int mainValue() { return m_mainValue; }
	int effectiveValue();
	
	bool holdTransmit() { return m_holdTransmit; }
	void setHoldTransmit(bool flag) { m_holdTransmit = flag; }
	
	virtual bool ignoreProperty(const QString& /*propertyName*/, bool /*isLoading*/);
	
public slots:
	void setDmxNum(int num)		{ m_dmxNum = num;	emit changed(); }
	void setIsEnabled(bool flag)	{ m_isEnabled = flag;	emit changed(); }
	void setIsHold(bool flag)	{ m_isHold = flag;	emit changed(); }
	
	virtual void setMainValue(int value);
	virtual void setValue(int value);

signals:
	void changed();
	
protected:
	int m_dmxNum;
	bool m_isEnabled;
	bool m_isHold;
	
	DmxClient *m_client;
	
	int m_mainValue;
	bool m_holdTransmit;
};


typedef QList<DmxChannel*> DmxChannelList;

class IndicatorWidget : public QWidget
{
	Q_OBJECT
public:
	IndicatorWidget(DmxChannel *channel, QWidget *parent);

protected slots:
	void valueChanged(int);

protected:
	void paintEvent(QPaintEvent *);

	QPixmap m_pixmap;
};

class OutputWindow : public QWidget
{
	Q_OBJECT
	
public:
	OutputWindow();
	
	DmxChannelList channelList() { return m_channelList; }
	
public slots:
	void mainLevelChanged(int);
	
	void storeChannels();
	
	bool holdTransmit(bool);
	bool isTransitOnHold() { return m_holdTransmit; }

protected:
	void setupGui();
	void setupChannels();
	
	void closeEvent(QCloseEvent*) { storeChannels(); }

protected slots:
	void generateSliderUI();
	
	void dmxChannelValueChanged(int);
	void sliderValueChanged(int);
	void nameChanged(QString);
	void channelNumChanged(int);
	void lockChannelChanged(bool);
	void enabledChanged(bool);
	
	//void showDisabledChanged(bool);
	
	void updateHoldUi(DmxChannel *chan);
	
	
protected:
	// Parent for the present control widgets
	QGroupBox *m_controlWidgetBase;
	
	// GridLayout for the sliders
	QGridLayout *m_sliderGrid;
	
	QCheckBox *m_showDisabled;
	
	DmxChannelList m_channelList;
	
	bool m_lockValueChanged;
	bool m_holdTransmit;
};


#endif
